<template>
  <el-header>
    <div class="page-header">
      <span class="page-text">{{ pageText }}</span>
      <el-popover
        placement="bottom"
        width="150"
        trigger="manual"
        v-model="isShow"
      >
        <span class="logout" @click="toLogout">退出登录<i class="el-icon-right icon"></i></span>
        <div class="header-right" slot="reference" @click="showLogout">
          <span class="el-icon-user-solid margin-right"></span>
          <span>admin</span>
          <span v-if="isShow" class="el-icon-caret-bottom"></span>
          <span v-else class="el-icon-caret-top"></span>
        </div>
      </el-popover>
    </div>
  </el-header>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "myHeader",
  data() {
    return {
      isShow: false,
    };
  },
  mounted() {
    // console.log('pagetext========',this.$route);
    let titleText = this.$route.meta.titleText
    if(titleText) {
      this.$store.commit('communication/changePageTextMu',titleText)
    }
    
  },
  computed: {
    ...mapState("communication", ["pageText"]),
  },
  methods: {
    showLogout() {
      this.isShow = !this.isShow;
    },
    toLogout() {
      this.$store.commit('user/clearToken')
      this.$router.push('/login')
      this.showLogout()
    }
  },
  watch:{
    $route() {
      let titleText = this.$route.meta.titleText
    if(titleText) {
      this.$store.commit('communication/changePageTextMu',titleText)
    }
    
    }
  }
};
</script>

<style lang="less" scoped>
.page-header {
  display: flex;
  justify-content: space-between;

  .header-right {
    cursor: pointer;
  }

  .page-text {
    font-size: 22px;
  }

  .margin-right {
    margin-right: 10px;
  }
  
}
.logout{
    margin-left: 32px;
    cursor: pointer;
    
    .icon{
      margin-left:10px;
    }
  }
</style>